package cs.entity;

import java.io.File;

/**
 * Represents an file linked with an user. <br>
 * It contains all informations of the file used by the GUI or the network to
 * (progression, name, size, state). <p> 
 * Package  cs.entity
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 */
public class UserFile{
	
	/**
	 * the recipient of the file
	 */
	private User remoteUser;
	
	/**
	 * the file to be sent
	 */
	private File file;
	
	/**
	 * Transfer progression
	 */
	private int progression;
	
	/**
	 * file to download name (in case we wan' to remane the file before download
	 * and for verification
	 */
	private String name;
	
	/**
	 * file to download size for verification (file downloaded matches the received file request)
	 */
	private long size;
	
	/**
	 * Transfer state
	 * ACCEPTED : the file has been approved, transfer can now take place
	 * REFUSED: the file has been rejected
	 * REQUEST: sending request to process
	 * COMPLETE: download/upload completed
	 *
	 */
	public static enum State {ACCEPTED, REFUSED, REQUEST, COMPLETED, FAILED};
	
	/**
	 * file state
	 */
	private State state;

	/**
	 * constructor of UserFile
	 * @param remote user which sending or receiving this file
	 * @param file 
	 */
	public UserFile(User remoteUser, File file) {
		super();
		this.remoteUser = remoteUser;
		this.file = file;
		name = file.getName();
		size = file.length();
		state = State.REQUEST;
		progression = 0 ;
	}

	public User getRemoteUser() {
		return remoteUser;
	}

	public void setRemoteUser(User remoteUser) {
		this.remoteUser = remoteUser;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public int getProgression() {
		return progression;
	}

	public void setProgression(int progression) {
		this.progression = progression;
	}
	
	public void setState(State state){
		this.state = state;
	}
	
	public State getState(){
		return state;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserFile other = (UserFile) obj;
		if (!getRemoteUser().equals(other.getRemoteUser()))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	} 
	
}
